package chapter7.section2;

//程序7-3：捕获多种异常
public class Summber3 {
	public static int sum(String op1, String op2) {
		int sum = 0, x = 0, y = 0;
		try {
			op1.trim();
			op2.trim();
			x = Integer.parseInt(op1);
			y = Integer.parseInt(op2);
			sum = x + y;
		} catch (NullPointerException e) {
			System.out.println("不能给我一个null的参数！");
		} catch (NumberFormatException e) {
			System.out.println("也不能给我一个不是数值型的字符串参数！");
		} catch (Exception e) {
			System.out.println("呵呵，再也没有异常会被放跑了！");
		}
		return sum;
	}

	public static void main(String[] args) {
		int result = sum("1", "2a");
		System.out.println("sum=" + result);
	}
}
